<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // ononline:网络连通的时候触发这个事件
        window.addEventListener("online", function() {
            alert("网络连接了")
        });
        // onoffline:网络断开的时候触发
        window.addEventListener("offline", function() {
            alert("网络断开了")
        })
    </script>
</body>

</html>